package com.japancompany.controller;

import com.japancompany.common.Result;
import com.japancompany.entity.Article;
import com.japancompany.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/")
    public String index(Model model) {
        // 获取推荐文章
        List<Article> recommendArticles = articleService.getRecommendArticles();
        model.addAttribute("recommendArticles", recommendArticles);
        
        // 获取置顶文章
        List<Article> topArticles = articleService.getTopArticles();
        model.addAttribute("topArticles", topArticles);
        
        // 获取最新文章
        List<Article> latestArticles = articleService.getLatestArticles();
        model.addAttribute("latestArticles", latestArticles);
        
        return "index";
    }

    @GetMapping("/about")
    public String about() {
        return "about";
    }

    @GetMapping("/contact")
    public String contact() {
        return "contact";
    }

    @GetMapping("/articles")
    public String articles() {
        return "articles";
    }
}